package main

func main() {

	println(majorityElement([]int{2, 2, 1, 1, 1, 2, 2}))
}

func majorityElement(nums []int) int {

	m := make(map[int]int)

	for _, num := range nums {
		if _, ok := m[num]; ok {
			m[num]++
			continue
		}

		m[num] = 1
	}

	max := 0
	kmax := 0

	for k, v := range m {
		println(k, ":", v)
		if v > max {
			max = v
			kmax = k
		}
	}

	return kmax
}
